package com.maxd.respository.selfUser;


import com.maxd.model.SelfUserBrowse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface SelfUserBrowseJpaRepository extends JpaRepository<SelfUserBrowse, Long> {

    //分页查询
    Page<SelfUserBrowse> findAll(Pageable pageable);

    //条件查询
    Page<SelfUserBrowse> findAll(Specification<SelfUserBrowse> specification, Pageable pageable);

    //根据商品id和用户id查询
    @Query(value = "from SelfUserBrowse s where s.goodsId=:goodsId and s.userId=:userId")
    SelfUserBrowse findByGoodsIdAndUserId(@Param("goodsId") Long goodsId, @Param("userId") Long userId);

    //根据商品id和用户id查询
    @Query(value = "select count(s.id) from SelfUserBrowse s left join Goods g on g.id = s.goodsId  where g.storeId=:storeId and s.createTime like concat('%',:createTime,'%')")
    int findSumByStoreId(@Param("storeId") Long storeId, @Param("createTime") String createTime);

}
